package utils.json.serializer;

import java.lang.reflect.Type;

import utils.Calendars;
import models.UserProp;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

/**
 * @author ultrafrog
 * @version 1.0, 2014-11-12
 * @since 1.0
 */
public class UserPropSerializer implements JsonSerializer<UserProp> {

	/* (non-Javadoc)
	 * @see com.google.gson.JsonSerializer#serialize(java.lang.Object, java.lang.reflect.Type, com.google.gson.JsonSerializationContext)
	 */
	@Override
	public JsonElement serialize(UserProp val, Type type, JsonSerializationContext ctx) {
		JsonObject obj = new JsonObject();
		obj.addProperty("subscribe", val.subscribe);
		obj.addProperty("nickname", val.nickname);
		obj.addProperty("sex", val.sex);
		obj.addProperty("country", val.country);
		obj.addProperty("province", val.province);
		obj.addProperty("city", val.city);
		obj.addProperty("language", val.language);
		obj.addProperty("headImgUrl", val.headImgUrl);
		obj.addProperty("subscribeTime", Calendars.format("yyyy-MM-dd HH:mm:ss", val.subscribeTime));
		obj.addProperty("unionId", val.unionId);
		obj.addProperty("subscribeName", val.getSubscribeName());
		obj.addProperty("sexName", val.getSexName());
		return obj;
	}
}
